<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ViewIssue</title>

<%@include file="editheader.jsp"%>

<script src="chosen/chosen.jquery.js" type="text/javascript"></script>

		
<script type="text/javascript" charset="utf-8">




var config = {
		'.chzn-select' : {},
		'.chzn-select-deselect' : {
			allow_single_deselect : true
		},
		'.chzn-select-no-single' : {
			disable_search_threshold : 10
		},
		'.chzn-select-no-results' : {
			no_results_text : 'Oops, nothing found!'
		},
		'.chzn-select-width' : {
			width : "95%"
		}
	};
	for ( var selector in config) {
		$(selector).chosen(config[selector]);
	}
	
var editissueid=0;

function EditPageInit(issueid, role) {

	editissueid = issueid;
	//alert("detail: "+ $("#hissuedetail").val());
	//CKEDITOR.instances.issuedetails.setData($("#hissuedetail").val());
	
	
			var idetail =  $("#hissuedetail").val();
		var i;
		for (i = 0; i < idetail.length; i++) {
			idetail = idetail.replaceAll("<br/>", "\n");
			//$("#vissuedetail").html(idetail);

		}
		//alert(idetail);
	 $("#issuedetails").val(idetail);
	 
	 
	 $.getJSON('../GetCategories?parentid=0', function(data) {
			var i = 0;
			$("#module").html("<option value=\"\"> </option>");
			for (i = 0; i < data.modules.length; i++) {
				$("#module").append(
						'<option value="'
								+ data.modules[i].id
								+ '">'
								+ data.modules[i].sectionname
								+ '</option>');
			}

			var mod = $("#hmodule").val();
			// $("#module1
			// option:contains("+mod+")").attr('selected',
			// 'selected');
			$("#module").val(mod);
			$("#module").trigger("liszt:updated");
			$("#module").chosen({allow_single_deselect : true});

		});
	 
	   var emodid = $("#hmodule").val().toString();

		$.getJSON('../GetCategories?parentid='+emodid, function(data) {
			var i = 0;
			$("#category").html("<option> </option>");
			for (i = 0; i < data.modules.length; i++) {
				$("#category").append(
						'<option value="'
								+ data.modules[i].id
								+ '">'
								+ data.modules[i].sectionname
								+ '</option>');
			}

			var cat = $("#hcategory").val();
			// $("#module1
			// option:contains("+mod+")").attr('selected',
			// 'selected');
			$("#category").val(cat);
			$("#category").trigger("liszt:updated");
			//$("#category").chosen();
			$("#category").chosen({allow_single_deselect : true});

		});

		var ecatid = $("#hcategory").val().toString();
		$.getJSON('../GetCategories?parentid='+ecatid, function(data) {
			var i = 0;
			$("#subcategory").html("<option> </option>");
			for (i = 0; i < data.modules.length; i++) {
				$("#subcategory").append(
						'<option value="'
								+ data.modules[i].id
								+ '">'
								+ data.modules[i].sectionname
								+ '</option>');
			}

			var subcat = $("#hsubcategory").val();
			// $("#module1
			// option:contains("+mod+")").attr('selected',
			// 'selected');
			$("#subcategory").val(subcat);
			$("#subcategory").trigger("liszt:updated");
			//$("#subcategory").chosen();
			$("#subcategory").chosen({allow_single_deselect : true});

		});
		
		
}
String.prototype.replaceAll = function(token, newToken, ignoreCase) {
	var _token;
	var str = this + "";
	var i = -1;

	if (typeof token === "string") {

		if (ignoreCase) {

			_token = token.toLowerCase();

			while ((i = str.toLowerCase().indexOf(token,
					i >= 0 ? i + newToken.length : 0)) !== -1) {
				str = str.substring(0, i) + newToken
						+ str.substring(i + token.length);
			}

		} else {
			return this.split(token).join(newToken);
		}

	}
	return str;
};



</script>


</head>
<body
	onload="EditPageInit(<%=request.getParameter("issueid")%>, <%=session.getAttribute("userrole")%>)">

	<%@include file="toppanel.jsp"%>

	<%@ page import="java.util.Map"%>
	<%
		wiki.GetDetails MyIssue = new wiki.GetDetails();
		String issueid = request.getParameter("issueid");
		Map<String, String>  MyIssueDetail =  MyIssue.GetIssueDetail(issueid);  

		//String module = MyIssueDetail.get("Module");
		//System.out.println("Module: " + module);
	%>

	<input type="hidden" id="hissuedetail"
		value="<%=MyIssueDetail.get("Details")%>" />

	<input type="hidden" id="hmodule"
		value="<%=MyIssueDetail.get("Moduleid")%>" />


	<input type="hidden" id="hcategory"
		value="<%=MyIssueDetail.get("Categoryid")%>" />
	<input type="hidden" id="hsubcategory"
		value="<%=MyIssueDetail.get("SubCategoryid")%>" />


	<input type="hidden" id="hversion"
		value="<%=MyIssueDetail.get("Version")%>" />


	<div style="width: 85%; padding-left: 8%">
		<div>

			<br /> Title: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
				type="text" id="issuetitle" class="span8" name="issuetitle"
				value="<%=MyIssueDetail.get("Title")%>" size="150"
				style="padding-left: 3px; padding-top: 3px; padding-bottom: 3px" />

			<em>&nbsp;&nbsp; &nbsp; &nbsp; Bugid:</em> &nbsp;<input class="span2"
				type="text" style="width: 100px;" tabindex="4" id="bugid"
				value="<%=MyIssueDetail.get("Bugid")%>">

			<div class="side-by-side clearfix" style="padding-top: 20px;">

				<em>Module: &nbsp;</em> <select
					data-placeholder="Select a module..." class="chzn-select-deselect"
					style="width: 200px;" id="module"></select> <select id="category"
					class="chzn-select" style="width: 200px;" tabindex="2">

				</select> <select id="subcategory" class="chzn-select" style="width: 200px;"
					tabindex="2">

				</select> <em>&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; Version:&nbsp;</em> <select
					class="chzn-select" id="version" multiple style="width: 350px;"
					tabindex="4">

				</select>


			</div>
			<br /> <br />
			<textarea id="issuedetails" rows="10" class="input-block-level"
				style="font-size: 14px; background-color: #f9f9f9;"></textarea>
				
						
			<br /> <input type="submit" id="editissuebtnsave" value="save"
				name="btnsave" class="btn" /> &nbsp;&nbsp;&nbsp; <input
				type="submit" id="btncancel" value="cancel" name="btncancel"
				class="btn" />
		</div>



	</div>



	



</body>
</html>